<?php
class DealSearch extends Deal
{
	public $createUserName;
	
	public function rules()
	{
		$parentRules = parent::rules();
		return CMap::mergeArray($parentRules, array(
			array( 'createUserName', 'safe', 'on'=>'search'),
		));
	}
	
	public function attributeLabels()
	{
		$parentLabels = parent::attributeLabels();
		return CMap::mergeArray($parentLabels, array(
			'createUserName'=>'Create User'
		));
	}
	
	public function search()
	{	
		$criteria=new CDbCriteria;
		$criteria->compare('createUserId',$this->createUserId);
		$criteria->compare('t.teamId',$this->teamId);
		$criteria->compare('referenceNo',$this->referenceNo,true);
		$criteria->compare('bank',$this->bank);
		$criteria->order = 'referenceNo';		
		if(!empty($this->createUserName)){
				$criteria->with = array(
					'createUser'=>array(
		        		'select'=>false,
				        'joinType'=>'INNER JOIN',
		        		'condition'=>'createUser.firstName LIKE "%'.$this->createUserName.'%" OR createUser.lastName LIKE "%'.$this->createUserName.'%"
		        		 OR createUser.username LIKE "%'.$this->createUserName.'%"',
					)
				);
		}
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria
		));
	}
}